export const GetRespnse = (model) => {
    let response = {};
    for (let key in model) {
        let ObjectValue = {};

        if (typeof model[key] == 'object') {
            if (model[key].length > 0) {
                let innerlist = [];
                for (let s = 0; s < 10; s++) {
                    innerlist.push(GetRespnse(model[key][0]));
                }
                response[key] = innerlist;
            } else {
                ObjectValue = GetRespnse(model[key])
                response[key] = ObjectValue;
            }

        }
        else {
            let keyValue = GetValueByKey(model[key]);
            response[key] = keyValue;
        }

    }
    return response;
}

const GetValueByKey = (key) => {

    switch (key) {
        case 'cstring':
            let cstring = GetCstring(10);
            return cstring;
            break;
        case 'string':
            let string = GetString(10);
            return string;
            break;
        case 'num':
            let num = Math.random(1, 10)
            return num;
            break;
        case 'key':
            break;
        default:
            return key
            break;
    }

}


const GetCstring = (count) => {
    let cstring = '';
    for (let i = 0; i < count; i++) {
        cstring += "\\u" + (Math.round(Math.random() * 20901) + 19968).toString(16);
    }
    return cstring;
}

const GetString = (count) => {
    count = count || 32;
    let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    let maxPos = $chars.length;
    let string = '';
    for (let i = 0; i < count; i++) {
        string += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return string;
}



export function getModel(model) {
    return {
        data: model,
        message: 'string',
        statusCode: 'string',
        success: false
    }
}
export const getOneResponse = (model) => {
    return GetRespnse(model);
}

export const getListResponse = (model, count) => {
    let list = [];
    for (let i = 0; i < count; i++) {
        list.push(GetRespnse(model));
    }
    return list;
}
